package com.hspedu.newData.dmsxl.哈希表;

import org.junit.Test;

import java.util.HashMap;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC1399统计最大组的数目 {

    public int countLargestGroup(int n) {

        HashMap<Integer, Integer> map = new HashMap<>();

        for (int i = 1; i <= n; i++) {
            int sum = 0;
            int k = i;
            while(k > 0){
                sum += k%10;
                k /= 10;
            }
            map.put(sum,map.getOrDefault(sum,0) + 1);
        }

        int max = 0;
        int count = 0;
        for (Integer value : map.values()) {
            if (max < value){
                max = value;
                count = 1;
            }else if (max == value){
                count++;
            }
        }


        return count;
    }


    @Test
    public void test() {
        // 测试代码

        int i = countLargestGroup(2);
        System.out.println(i);
    }
}
